package com.swss.g.assets.action;

import java.io.File;
import java.net.URLEncoder;
import java.util.List;

import com.swss.g.assets.bean.Asset;
import com.swss.g.assets.bean.AstFinAudit;
import com.swss.g.assets.bean.AstRange;
import com.swss.g.assets.service.AssetService;
import com.swss.g.base.BaseAction;
import com.swss.g.sys.service.CurrentPeriodService;
import com.swss.g.sys.service.SysService;
import com.swss.g.user.bean.Role;
import com.swss.g.user.bean.User;
import com.swss.g.user.service.UserService;
import com.swss.util.Pagination;

public class financeAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3016348148306946228L;
	protected String date;
	protected List<?> fundSubList;
	protected List<?> useDirList;
	protected List<?> nowStatusList;
	protected List<?> astSourceList;
	protected List<?> chargeOffDeptList;
	protected List<?> financeUserList;
	
	//资产列表
	protected List<?> astList;

	// 上传图片
	protected File[] pics;
	protected String[] picFileNames;
	protected String[] picContentTypes;
	// 上传发票
	protected File bill;
	protected String billFileName;
	protected String billContentTypes;
	// 资产类型
	protected char astType;
	//选中的将要审核编号
	protected String auditNoArray;
	//菜单查询或条件筛选标记
	Integer clearbean; // 1.菜单查询

	/**
	 * bean
	 */

	protected User user;

	protected Pagination<?> pagination;

	protected Role role;

	protected Asset asset;
	//财务审核信息对象
	protected AstFinAudit astFinAudit;
	
	private AstRange astRange;

	/**
	 * service
	 * 
	 * @return
	 */
	protected AssetService assetService;
	protected CurrentPeriodService currentPeriodService;
	protected UserService userService;
	protected SysService sysService;

	
	/**
	 * 未审数据查询
	 * @param deptNo 单位编号 
	 * getAssetType() //判断是否条件查询并设置标记 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String findNotAduit() throws Exception{
		String deptNo = this.getSessionAttr("user", User.class).getDeptNo().trim();
		chargeOffDeptList = this.getSysService().getChargeOffDept();
		if(this.msg!=null){
			this.msg=new String(msg.getBytes("iso8859-1"), "UTF-8");
		}
		try {
		    asset = this.getAssetType("S"); 
			if(this.pagination==null){
				pagination= new Pagination();
			}
			pagination=this.assetService.findAstFinByExample(pagination,asset,astRange,deptNo);
			pagination.setUrl("/swss" + this.getRequest().getServletPath());
			
			if(this.pagination.getRowcount()==0)
				this.msg="无满足条件的记录";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return INPUT;
		}
		return "resFinAduit";
	}
	
	//通过审核页面初始化
	public String initGoAduit(){
		
		//填充页面下拉框
		String finUser = this.getSessionAttr("user",User.class).getFin().toString(); 
	    auditNoArray = this.getRequest().getParameter("auditNoArray");
		
		try{
			financeUserList = this.sysService.getFinanceUser(finUser);
			fundSubList=this.sysService.getFundSub();
		}catch(Exception e){
			e.printStackTrace();
			return INPUT;
		}
		return "showGoAduit";
	}

	//通过财务审核 5
	public String goAduit(){
		
		try {
			if (astFinAudit != null)
				this.code = this.assetService.astFinAuditUpdate(astFinAudit,auditNoArray);
			    this.msg = URLEncoder.encode("审核成功","utf-8");
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
		
		return "findNotAduit";
	}
	
	//退回页面初始化
	public String initBackaduit(){
		try{
			auditNoArray = this.getRequest().getParameter("auditNoArray");
		}catch(Exception e){
			e.printStackTrace();
			return INPUT;
		}
		return "gobackaduit";
	}
	
	//退回财务审核 2
	public String backAduit(){
		try{
			String returreas = this.getRequest().getParameter("returreas");
			auditNoArray = this.getRequest().getParameter("auditNoArray");
			this.code=this.assetService.astFinAuditBack(auditNoArray, returreas);
			this.msg = URLEncoder.encode("退回成功","utf-8");
		}catch(Exception e){
			e.printStackTrace();
			return INPUT;
		}
		return "findNotAduit";
	}
	/**
	 * 查询财务已审
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String finthroughAduit(){
		String deptNo = this.getSessionAttr("user", User.class).getDeptNo().trim();
		try {
			if (this.msg != null) {
				this.msg = new String(msg.getBytes("iso8859-1"), "UTF-8");
			}
			asset=this.getAssetType("S");
			chargeOffDeptList = this.getSysService().getChargeOffDept();
			if (this.pagination == null) {
				pagination = new Pagination();
			}
			pagination = this.assetService.findthroughFinByExample(pagination,asset,astRange,deptNo);
			pagination.setUrl("/swss" + this.getRequest().getServletPath());
			if (this.pagination.getRowcount() == 0)
				this.msg = "无满足条件的记录";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return INPUT;
		}
		
		return "resFinThrAudit";
	}
	/**
	 * 财务恢复
	 * @return
	 */
	public String recoveryAduit(){
		
		try{
			auditNoArray = this.getRequest().getParameter("auditNoArray");
			this.code=this.assetService.astFinthroughAudit(auditNoArray);
			this.msg = URLEncoder.encode("恢复成功","utf-8");
		}catch(Exception e){
			e.printStackTrace();
			return INPUT;
		}
		return "FinThrAudit";
	}
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Pagination<?> getPagination() {
		return pagination;
	}

	public void setPagination(Pagination<?> pagination) {
		this.pagination = pagination;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public SysService getSysService() {
		return sysService;
	}

	public void setSysService(SysService sysService) {
		this.sysService = sysService;
	}

	public List<?> getFundSubList() {
		return fundSubList;
	}

	public void setFundSubList(List<?> fundSubList) {
		this.fundSubList = fundSubList;
	}

	public List<?> getUseDirList() {
		return useDirList;
	}

	public void setUseDirList(List<?> useDirList) {
		this.useDirList = useDirList;
	}

	public List<?> getNowStatusList() {
		return nowStatusList;
	}

	public void setNowStatusList(List<?> nowStatusList) {
		this.nowStatusList = nowStatusList;
	}

	public List<?> getAstSourceList() {
		return astSourceList;
	}

	public void setAstSourceList(List<?> astSourceList) {
		this.astSourceList = astSourceList;
	}

	public CurrentPeriodService getCurrentPeriodService() {
		return currentPeriodService;
	}

	public void setCurrentPeriodService(
			CurrentPeriodService currentPeriodService) {
		this.currentPeriodService = currentPeriodService;
	}

	public Asset getAsset() {
		return asset;
	}

	public void setAsset(Asset asset) {
		this.asset = asset;
	}

	public AssetService getAssetService() {
		return assetService;
	}

	public void setAssetService(AssetService assetService) {
		this.assetService = assetService;
	}

	public List<?> getChargeOffDeptList() {
		return chargeOffDeptList;
	}

	public void setChargeOffDeptList(List<?> chargeOffDeptList) {
		this.chargeOffDeptList = chargeOffDeptList;
	}

	public File[] getPic() {
		return pics;
	}

	public void setPic(File[] pic) {
		this.pics = pic;
	}

	public String[] getPicFileName() {
		return picFileNames;
	}

	public void setPicFileName(String[] picFileName) {
		this.picFileNames = picFileName;
	}

	public String[] getPicContentType() {
		return picContentTypes;
	}

	public void setPicContentType(String[] picContentType) {
		this.picContentTypes = picContentType;
	}

	public File getBill() {
		return bill;
	}

	public void setBill(File bill) {
		this.bill = bill;
	}

	public String getBillFileName() {
		return billFileName;
	}

	public void setBillFileName(String billFileName) {
		this.billFileName = billFileName;
	}

	public String getBillContentTypes() {
		return billContentTypes;
	}

	public void setBillContentTypes(String billContentTypes) {
		this.billContentTypes = billContentTypes;
	}

	public char getAstType() {
		return astType;
	}

	public void setAstType(char astType) {
		this.astType = astType;
	}

	public List<?> getAstList() {
		return astList;
	}

	public void setAstList(List<?> astList) {
		this.astList = astList;
	}

	public List<?> getFinanceUserList() {
		return financeUserList;
	}

	public void setFinanceUserList(List<?> financeUserList) {
		this.financeUserList = financeUserList;
	}

	public AstFinAudit getAstFinAudit() {
		return astFinAudit;
	}

	public void setAstFinAudit(AstFinAudit astFinAudit) {
		this.astFinAudit = astFinAudit;
	}

	public String getAuditNoArray() {
		return auditNoArray;
	}

	public void setAuditNoArray(String auditNoArray) {
		this.auditNoArray = auditNoArray;
	}

	public Integer getClearbean() {
		return clearbean;
	}

	public void setClearbean(Integer clearbean) {
		this.clearbean = clearbean;
	}
	
    public AstRange getAstRange() {
		return astRange;
	}

	public void setAstRange(AstRange astRange) {
		this.astRange = astRange;
	}

	/**
     * 判断asset对象是否为条件查询或默认查询内容
     * 对相关系统 设备，家具等设置标记 astmark S、Q等
     * @return
     */
    public Asset getAssetType(String astType) {
		// clearbean=1 清空session
		if (this.clearbean != null && this.clearbean == 1) {
			this.setSessionAttr("searchBean", null);
		  } else {
			if (asset != null) {
				this.setSessionAttr("searchBean", asset);
			} else {
				asset = this.getSessionAttr("searchBean", null);
			}
		}
		if (asset == null) {
			asset = new Asset();
			asset.setAstMark(astType);
		} else
			asset.setAstMark(astType);
		return asset;
	}
}
